package com.pet_service.sms;

import cn.hutool.http.HttpUtil;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @author 邹全伸
 * @version 1.0
 * @date 2025-10-05 14:41
 */
@Service
public class IHuYiSMSUtil {
    @Value("${ihuyi.sms.account}")
    private String account;

    @Value("${ihuyi.sms.apikey}")
    private String apikey;

    //真实发送
    public String sendCode(String phone, String verifyCode) {
        String sendResult = null;
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("account", account);// APPID
        paramMap.put("password", apikey);// APPID KEY
        paramMap.put("mobile", phone);// 要发送的手机号
        paramMap.put("content", "您的验证码是：" + verifyCode + "。请不要把验证码泄露给其他人。");
        String s = HttpUtil.get("https://106.ihuyi.com/webservice/sms.php?method=Submit", paramMap);
        // Jsoup 包下的 Document 、 Jsoup
        Document parse = Jsoup.parse(s);
        if (2 == Integer.parseInt(parse.select("code").get(0).text())) {
            sendResult = "发送成功";
        } else {
            sendResult = "发送失败";
        }
        return sendResult;
    }

    // 测试发送验证码
    public String testSendCode(String mobile, String code) {
        return mobile+"发送成功!您的验证码是：" + code + "。请不要把验证码泄露给其他人。";
    }
}
